home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Source Code
/
Pascal
/
Snippets
/
PNL Libraries
/
Libraries
/
SpriteWorld
/
SpriteWorld files
/
Interfaces
/
Sprite.p
< prev
next >
Wrap
Text File
|
1996-11-24
|
9KB
|
177 lines
{/--------------------------------------------------------------------------------------}
{ Sprite.h}
{}
{ Portions are copyright: c 1991-94 Tony Myles, All rights reserved worldwide.}
{}
{ Description: constants, structures, and prototypes for sprites}
{/--------------------------------------------------------------------------------------}
unit Sprite;
interface
uses
{$IFC undefined THINK_Pascal}
Types,
{$ENDC}
QDOffscreen, SWCommonHeaders, SpriteFrame;
{$PUSH}
{$ALIGN MAC68K}
{/--------------------------------------------------------------------------------------}
{ sprite type definitions}
{/--------------------------------------------------------------------------------------}
type
RemovalType = SignedByte;
const
kSWDontRemoveSprite = 0;
kSWRemoveSprite = 1;
kSWRemoveAndDisposeSprite = 2;
type
SpritePtr = ^SpriteRec;
SpritePHdl = ^SpritePtr;
RectArrayPtr = ^RectArray;
RectArrayHdl = ^RectArrayPtr;
{$IFC undefined THINK_Pascal}
FrameProcPtr = procedure (srcSpriteP: SpritePtr; curFrameP: FramePtr; var frameIndex: longint );
DrawProcPtr = procedure (srcFrameP: FramePtr; dstFrameP: FramePtr; var srcRect: Rect; var dstRect: Rect);
MoveProcPtr = procedure (srcSpriteP: SpritePtr );
CollideProcPtr = procedure ( srcSpriteP: SpritePtr; dstSpriteP: SpritePtr; var sectRect: Rect );
{$ELSEC}
FrameProcPtr = ProcPtr;
DrawProcPtr = ProcPtr;
MoveProcPtr = ProcPtr;
CollideProcPtr = ProcPtr;
{$ENDC}
FramePtrArray = array[0..0] of FramePtr;
FramePtrArrayPtr = ^FramePtrArray;
{/--------------------------------------------------------------------------------------}
{ Rect array data structure}
{/--------------------------------------------------------------------------------------}
RectArray = record
numFrames: Integer;
frameRects: array[0..0] of Rect;
end;
{/--------------------------------------------------------------------------------------}
{ sprite data structure}
{/--------------------------------------------------------------------------------------}
SpriteRec = record
nextSpriteP: SpritePtr; { next sprite in that layer}
prevSpriteP: SpritePtr; { previous sprite in that layer}
nextActiveSpriteP: SpritePtr; { next active sprite in the SpriteWorld}
nextIdleSpriteP: SpritePtr; { next idle sprite in the SpriteWorld}
{ drawing fields}
isVisible: Boolean; { draw the sprite?}
needsToBeDrawn: Boolean; { sprite has changed, needs to be drawn}
needsToBeErased: Boolean; { sprite needs to be erased onscreen}
isUnderTiles: Boolean; { is the sprite behind the tiles?}
destFrameRect: Rect; { frame destination rectangle}
oldFrameRect: Rect; { last frame destination rectangle}
deltaFrameRect: Rect; { union of the sprite's lastRect and curRect}
frameDrawProc: DrawProcPtr; { callback to draw sprite}
{ drawing fields for scrolling routines}
clippedSourceRect: Rect; { source sprite frame rect after clipping}
destOffscreenRect: Rect; { sprite's dest rect after clipping and offset}
oldOffscreenRect: Rect; { the destOffscreenRect from the previous frame}
destRectIsVisible: Boolean; { is destOffscreenRect visible on screen?}
oldRectIsVisible: Boolean; { was oldOffscreenRect visible on screen?}
{ frame fields}
frameArray: FrameArrayPtr; { array of frames}
curFrameP: FramePtr; { current frame}
numFrames: LongInt; { number of frames}
maxFrames: LongInt; { maximum number of frames}
frameTimeInterval: LongInt; { time interval to advance frame}
timeOfLastFrameChange: LongInt; { time (from runningTimeCount) frame was last changed}
frameAdvance: LongInt; { amount to adjust frame index}
curFrameIndex: LongInt; { current frame index}
firstFrameIndex: LongInt; { first frame to advance}
lastFrameIndex: LongInt; { last frame to advance}
frameChangeProc: FrameProcPtr; { callback to change frames}
{ movement fields}
moveTimeInterval: LongInt; { time interval to move sprite}
timeOfLastMove: LongInt; { time (from runningTimeCount) sprite was last moved}
horizMoveDelta: Integer; { horizontal movement delta}
vertMoveDelta: Integer; { vertical movement delta}
moveBoundsRect: Rect; { bounds of the sprite's movement}
spriteMoveProc: MoveProcPtr; { callback to handle movement}
{ collision detection}
spriteCollideProc: CollideProcPtr; { callback to handle collisions}
{ miscellaneous}
sharedPictGWorld: GWorldPtr; { if common GWorld used for frames, here it is}
sharedMaskGWorld: GWorldPtr; { same for mask}
spriteRemoval: RemovalType; { whether to remove sprite, and if so how}
userData: LongInt; { reserved for user}
end;
function SWCreateSprite (var newSpriteP: SpritePtr; spriteStorageP: Ptr; maxFrames: Integer): OSErr;
function SWCreateSpriteFromCicnResource (destSpriteWorld: SpriteWorldPtr; var newSpriteP: SpritePtr; spriteStorageP: Ptr; cIconID: Integer; maxFrames: Integer; maskKind: MaskType): OSErr;
function SWCreateSpriteFromPictResource (destSpriteWorld: SpriteWorldPtr; var newSpriteP: SpritePtr; spriteStorageP: Ptr; pictResID: Integer; maskResID: Integer; maxFrames: Integer; maskKind: MaskType): OSErr;
function SWCreateSpriteFromSinglePict (destSpriteWorld: SpriteWorldPtr; var newSpriteP: SpritePtr; spriteStorageP: Ptr; pictResID: Integer; maskResID: Integer; frameWidth: Integer; maskKind: MaskType): OSErr;
function SWCreateSpriteFromSinglePictXY (destSpriteWorld: SpriteWorldPtr; var newSpriteP: SpritePtr; spriteStorageP: Ptr; pictResID: Integer; maskResID: Integer; frameWidth: Integer; frameHeight: Integer; borderWidth: Integer; MaxFrames: Integer; maskKind: MaskType): OSErr;
function SWUpdateSpriteFromPictResource (theSpriteP: SpritePtr; pictResID: Integer): OSErr;
function SWCloneSprite (cloneSpriteP: SpritePtr; var newSpriteP: SpritePtr; spriteStorageP: Ptr): OSErr;
procedure SWRemoveSpriteFromAnimation (spriteWorldP: SpriteWorldPtr; spriteP: SpritePtr; disposeOfSprite: Boolean);
procedure SWDisposeSprite (oldSpriteP: SpritePtr);
procedure SWCloseSprite (deadSpriteP: SpritePtr);
procedure SWLockSprite (srcSpriteP: SpritePtr);
procedure SWUnlockSprite (srcSpriteP: SpritePtr);
function SWSetSpriteDrawProc (srcSpriteP: SpritePtr; drawProc: DrawProcPtr): OSErr;
procedure SWStdSpriteDrawProc (srcFrameP: FramePtr; dstFrameP: FramePtr; var srcRect: Rect; var dstRect: Rect);
function SWAddFrame (srcSpriteP: SpritePtr; newFrameP: FramePtr): OSErr;
procedure SWRemoveFrame (srcSpriteP: SpritePtr; oldFrameP: FramePtr);
procedure SWSetCurrentFrame (srcSpriteP: SpritePtr; curFrameP: FramePtr);
procedure SWSetCurrentFrameIndex (srcSpriteP: SpritePtr; frameIndex: Integer);
procedure SWSetSpriteFrameAdvance (srcSpriteP: SpritePtr; frameAdvance: Integer);
procedure SWSetSpriteFrameRange (srcSpriteP: SpritePtr; firstFrameIndex: Integer; lastFrameIndex: Integer);
procedure SWSetSpriteFrameTime (srcSpriteP: SpritePtr; timeInterval: LongInt);
procedure SWSetSpriteFrameProc (srcSpriteP: SpritePtr; frameProc: FrameProcPtr);
procedure SWMoveSprite (srcSpriteP: SpritePtr; horizLoc: Integer; vertLoc: Integer);
procedure SWOffsetSprite (srcSpriteP: SpritePtr; horizOffset: Integer; vertOffset: Integer);
procedure SWSetSpriteLocation (srcSpriteP: SpritePtr; horizLoc: Integer; vertLoc: Integer);
procedure SWSetSpriteMoveBounds (srcSpriteP: SpritePtr; var moveBoundsRect: Rect);
procedure SWSetSpriteMoveDelta (srcSpriteP: SpritePtr; horizDelta: Integer; vertDelta: Integer);
procedure SWSetSpriteMoveTime (srcSpriteP: SpritePtr; timeInterval: LongInt);
procedure SWSetSpriteMoveProc (srcSpriteP: SpritePtr; moveProc: MoveProcPtr);
procedure SWBounceSprite (srcSpriteP: SpritePtr);
procedure SWWrapSprite (srcSpriteP: SpritePtr);
procedure SWSetSpriteCollideProc (srcSpriteP: SpritePtr; collideProc: CollideProcPtr);
function SWRegionCollision (srcSpriteP: SpritePtr; dstSpriteP: SpritePtr): Boolean;
function SWRadiusCollision (srcSpriteP: SpritePtr; dstSpriteP: SpritePtr): Boolean;
function SWPixelCollision (srcSpriteP: SpritePtr; dstSpriteP: SpritePtr): Boolean;
procedure SWSetSpriteVisible (srcSpriteP: SpritePtr; isVisible: Boolean);
function SWIsSpriteInRect (srcSpriteP: SpritePtr; var testRect: Rect): Boolean;
function SWIsSpriteFullyInRect (srcSpriteP: SpritePtr; var testRect: Rect): Boolean;
function SWIsPointInSprite (srcSpriteP: SpritePtr; testPoint: Point): Boolean;
{$ALIGN RESET}
{$POP}
{$IFC not undefined THINK_Pascal}
implementation
{$ENDC}
end.